package com.dhj.yygh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dhj.yygh.common.result.MyResult;
import com.dhj.yygh.model.user.Patient;
import com.dhj.yygh.model.user.UserInfo;
import com.dhj.yygh.service.PatientService;
import com.dhj.yygh.service.UserInfoService;
import com.dhj.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "后台管理用户相关接口")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private PatientService patientService;

    // 用户列表接口
    @ApiOperation("条件查询分页获取用户列表")
    @GetMapping("/getUserList/{page}/{limit}")
    public MyResult<Page<UserInfo>> getUserList(
            @PathVariable("page") Long page,
            @PathVariable("limit") Long limit,
            UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> infoPage = new Page<>(page, limit);
        Page<UserInfo> userInfoPage = userInfoService.getUserList(infoPage, userInfoQueryVo);

        return MyResult.ok(userInfoPage);
    }

    @ApiOperation("根据用户 id 修改用户状态")
    @GetMapping("/lock/{id}/{status}")
    public MyResult lockUser(
            @PathVariable("id") Long id,
            @PathVariable("status") Integer status) {

        if (userInfoService.lockUser(id, status)) {
            return MyResult.ok();
        }

        return MyResult.fail();
    }


    @ApiOperation("根据用户 id 查询其详细信息")
    @GetMapping("/getUserInfoDetail/{id}")
    public MyResult<Map<String, Object>> getUserInfoDetail(@PathVariable("id") Long id) {
        Map<String, Object> resutlMap = userInfoService.userInfoDetail(id);

        return MyResult.ok(resutlMap);
    }

    @ApiOperation("认证审批用户")
    @PutMapping("/authUserInfo/{id}/{auth_status}")
    public MyResult authUserInfo(
            @PathVariable("id") Long id,
            @PathVariable("auth_status") Integer auth_status) {

        userInfoService.authUserInfo(id, auth_status);

        return MyResult.ok();
    }

    @ApiOperation("根据就诊人 id 获取就诊人信息")
    @GetMapping("/getPatientById/{id}")
    public Patient getPatientById(@PathVariable("id") Long id) {
        Patient patientById = patientService.getPatientById(id);
        return patientById;
    }
}
